<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="flex-1" :model="formState" :label-col="{ style: { width: '70px' } }">
        <a-form-item name="dateRange" label="日期范围" class="w-[330px]">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <BaseTable :loading="loading" column-code="000043" fill :data-source="tableData" bordered :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex == 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickDetail(record)"> 明细 </a-button>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <Edit v-model:open="editOpen" :time="formState.dateRange" :row-data="rowData" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
// import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
// import { post } from '@/utils/request'
import SearchContainer from '@/components/SearchContainer'
import useUserStore from '@/store/user'
import Edit from './Edit.vue'

const { empId } = useUserStore()

const rowData = ref({})
const editOpen = ref(false)
const formRef = ref(null)
const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
})
const onClickDetail = (row) => {
  rowData.value = { ...row }
  editOpen.value = true
}

// const onHandleReturn = async (row) => {

// }
const { loading, tableData, pagination, getData } = useTable({
  url: '/outp/mzys/getPhysicianWorkloadInquiryList',
  immediate: true,
  params: formState.value,
  formatParams: (params) => {
    return {
      ysbh: empId,
      stdate: params['dateRange']?.[0],
      eddate: params['dateRange']?.[1],
      status: '1'
    }
  }
})
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
